<html>
<head>
<meta charset="UTF-8">
<title>定时调度配置新增</title>
	<link  id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.ext.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout">
	<form id="ff" method="post">
		<div class="esaas-info-title">定时调度配置信息</div>
		<table class="esaas-info-add-table">
			<tr>
				<td width="15%" align="right">定时作业编号：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="jobCode" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">定时作业描述：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="jobDesc" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">执行节点标识：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="agentId" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">所属系统：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
				    name="subsCode" id="subsCode" data-options="required:true,disabled: true"
				    style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">作业类类型：</td>
				<td width="35%"><select class="easyui-combobox"
					id="jobClassType" name="jobClassType"
					style="width: 100%; height: 25px;"
					data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:JOB_CLASS_TYPE, onSelect: onChangeJobType">
				</select></td>
				<td width="15%" align="right">作业实现类：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="jobClass" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>

			</tr>
			<tr>
				<td width="15%" align="right">作业类方法：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="jobMethod" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right"><span id="serviceVersionLabel">服务版本：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="serviceVersion"
					name="serviceVersion" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>

			</tr>
			<tr>
				<td width="15%" align="right"><span id="serviceGroupLabel">服务组别：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="serviceGroup"
					name="serviceGroup" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="18%" align="right"><span id="serviceTimeoutLabel">服务超时时间(毫秒)：</span></td>
				<td width="35%"><input class="easyui-textbox" type="text" id="serviceTimeout"
					name="serviceTimeout" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">失败重试次数：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="againTime" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">重试间隔秒数：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="retrySecond" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">作业状态：</td>
				<td width="35%"><select class="easyui-combobox"
					id="jobState" name="jobState"
					style="width: 100%; height: 25px;"
					data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:JOB_STATE">
				</select></td>
				<td width="15%" align="right">耗时（秒）：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
				    name="costTime" data-options="required:false"
				    style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">上一次执行时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
				    name="lastExecuteTime" data-options="required:false"
				    style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">下一次执行时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
				    name="nextExecuteTime" data-options="required:false"
				    style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">执行周期：</td>
				<td width="35%"><input class="easyui-textbox"
									   id="cronExpression" name="cronExpression" data-options="required:true"
									   style="width: 100%; height: 25px;"></input>
					<select class="easyui-combobox" type="text" id="select_cron" style="width: 20%; height: 25px;"
							data-options="required:false,editable:false,valueField:'value',textField:'text',onSelect:selectCron">
						<option value="day">每天</option>
						<option value="nDay">N天</option>
						<option value="hours">每小时</option>
						<option value="nHours">N小时</option>
						<option value="nMinutes">N分钟</option>
						<option value="week">每星期</option>
						<option value="month">每月</option>
					</select>
					<select class="easyui-combobox" id="week" style="width: 20%; height: 25px;"
							data-options="required:false,editable:false,valueField:'value',textField:'text'">
						<option value="1">周一</option>
						<option value="2">周二</option>
						<option value="3">周三</option>
						<option value="4">周四</option>
						<option value="5">周五</option>
						<option value="6">周六</option>
						<option value="7">周日</option>
					</select>
					<select class="easyui-combobox" id="day" style="width: 25%; height: 25px;" buttonText="天"
							data-options="required:false,editable:true,valueField:'value',textField:'text'">
					</select>
					<select class="easyui-combobox" id="hours" style="width: 25%; height: 25px;" buttonText="时"
							data-options="required:false,editable:true,valueField:'value',textField:'text'">
					</select>
					<select class="easyui-combobox" id="minutes" style="width: 25%; height: 25px;" buttonText="分"
							data-options="required:false,editable:true,valueField:'value',textField:'text'">
					</select>
				</td>
			</tr>
			<tr>
				<td width="15%" align="right">备注：</td>
				<td width="85%" colspan="3"><input class="easyui-textbox" type="text"
					name="remark" data-options="required:false, multiline: true"
					style="width: 100%; height: 50px;"></input></td>
			</tr>
		</table>
	</form>
	<div class="esaas-info-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton " iconCls="icon-ok" onclick="submitForm()" style="width:90px">&nbsp;保&nbsp;存&nbsp;</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="closeForm()" style="width:90px">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>
		$(function() {
		    addTitle("新增");
			onChangeJobType(null);
			cronShowInit();
		});

		function cronShowInit(){
			$("#cronExpression").next().hide();
			onChangeJobType(null);
			var hoursData = [{}];
			for (var i = 0; i < 24; i++) {
				hoursData.push({ text: i, value: i });
			}
			$("#hours").combobox("loadData", hoursData);
			var minutesData = [{}];
			for (var i = 0; i < 60; i++) {
				minutesData.push({ text: i, value: i });
			}
			$("#minutes").combobox("loadData", minutesData);
			var dayData = [{}];
			for (var i = 1; i < 32; i++) {
				dayData.push({ text: i, value: i });
			}
			$("#day").combobox("loadData", dayData);
			$("#week").next().hide();
			$("#day").next().hide();
		}

		function selectCron(){
			var selectValue=$("#select_cron").combobox("getValue");
			if(selectValue=="day" ||selectValue=="nHours"){
				$("#week").next().hide();
				$("#day").next().hide();
				$("#hours").next().show();
				$("#minutes").next().show();
			}else if(selectValue=="month"||selectValue=="nDay"){
				$("#week").next().hide();
				$("#day").next().show();
				$("#hours").next().show();
				$("#minutes").next().show();
			}else if(selectValue=="hours"||selectValue=="nMinutes"){
				$("#week").next().hide();
				$("#day").next().hide();
				$("#hours").next().hide();
				$("#minutes").next().show();
			}else if(selectValue=="week"){
				$("#week").next().show();
				$("#day").next().hide();
				$("#hours").next().show();
				$("#minutes").next().show();
			}
		}
		function createCron(){
			var selectValue=$("#select_cron").combobox("getValue");
			var cron="";
			if(selectValue=="week"){
				cron="? * "+$("#week").combobox("getValue");
				cron=$("#hours").combobox("getText")+" "+cron;
				cron=$("#minutes").combobox("getText")+" "+cron;
			}else if(selectValue=="month"){
				cron="* ?";
				cron=$("#day").combobox("getValue")+" "+cron;
				cron=$("#hours").combobox("getText")+" "+cron;
				cron=$("#minutes").combobox("getText")+" "+cron;
			}else if(selectValue=="nDay"){
				cron="*/"+$("#day").combobox("getValue")+" * ?";
				cron=$("#hours").combobox("getText")+" "+cron;
				cron=$("#minutes").combobox("getText")+" "+cron;
			}else if(selectValue=="day"){
				cron="* * ?";
				cron=$("#hours").combobox("getText")+" "+cron;
				cron=$("#minutes").combobox("getText")+" "+cron;
			}else if(selectValue=="nHours"){
				cron="*/"+$("#hours").combobox("getText")+" * * ?";
				cron=$("#minutes").combobox("getText")+" "+cron;
			}else if(selectValue=="hours"){
				cron=$("#minutes").combobox("getText")+" * * * ?";
			}else{
				cron="*/"+$("#minutes").combobox("getText")+" * * * ?";
			}
			cron="0 "+cron;
			$("#cronExpression").textbox('setValue',cron);
		}

		function submitForm() {
			createCron();
			if (!$('#ff').form('validate'))
				return;
			var jsonData = $("#ff").serializeJson();
			$.restfulPostJson('../../api/s/srvs/cron/conf', jsonData, function(data) {
				window.parent.reloadList();
			});
		};

		function onChangeJobType(data){
			console.log(data);
			$("#subsCode").textbox('setValue',$.getUrlParam('subsCode'));
			if(data && (data.enname == 'hsf' || data.enname == 'dubbo')) {
				$("#serviceVersionLabel").show();
				$("#serviceVersion").next().show();
				$("#serviceGroupLabel").show();
				$("#serviceGroup").next().show();
				$("#serviceTimeoutLabel").show();
				$("#serviceTimeout").next().show();

				$("#serviceVersion").textbox('textbox').validatebox({required: true});
			} else {
				$("#serviceVersionLabel").hide();
				$("#serviceVersion").next().hide();
				$("#serviceGroupLabel").hide();
				$("#serviceGroup").next().hide();
				$("#serviceTimeoutLabel").hide();
				$("#serviceTimeout").next().hide();

				$("#serviceVersion").textbox('textbox').validatebox({required: false});
				$("#serviceVersion").textbox('setValue', '');
				$("#serviceGroup").textbox('setValue', '');
				$("#serviceTimeout").textbox('setValue', '');
			}
		}

		function closeForm() {
			window.parent.JLEUtil.closewin();
		}
	</script>
</body>
</html>